<template>
  <div>
    <el-form :inline="true" :model="search" class="demo-form-inline">
      <el-row class="table-head-box">
         <el-col :span="4" class="flex flex-start">
          <el-button type="primary" icon="el-icon-plus"    plain @click="addHandler()">添加常用语</el-button>
        </el-col>
        <el-col :span="20" class="flex flex-end input-box">
          <el-input v-model="search.lkParam.titleName" clearable placeholder="标题"></el-input>
          <el-button type="primary" icon="el-icon-search" @click="searchHandler">查询</el-button>
        </el-col>

      </el-row>
      
    </el-form>
    <el-table :data="pageList" border style="width: 100%" tooltip-effect="dark" size="mini">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column  prop="titleId" label="编号"  width="200">
      </el-table-column>
      <el-table-column  prop="titleName" label="标题名称">
      </el-table-column>
      <el-table-column prop="titleDesc" label="标题描述">
      </el-table-column>
       <el-table-column prop="titleParentName" label="父类标题">
      </el-table-column>
       <el-table-column prop="titleLevel" label="标题等级">
      </el-table-column>
      
      <!-- <el-table-column prop="status" label="状态" width="300">
         <template slot-scope="scope">
         <el-switch
          v-model="scope.row.status"
          active-color="#13ce66"
          inactive-color="#ff4949"
          :active-value="1"
          :inactive-value="2"
          @change="updateStatusHandler(scope.row)"
          >
        </el-switch>
        </template>
      </el-table-column> -->
      <el-table-column fixed="right" label="操作" width="260">
        <template slot-scope="scope">
          <!-- <el-button type="primary" size="mini" icon="el-icon-edit" @click="updateHandler(scope.$index, scope.row)">编辑</el-button> -->
          <!-- <el-button v-if="scope.row.titleLevel==1"  type="success"  size="mini" icon="el-icon-plus" @click="addSubHander(scope.$index, scope.row)">子项</el-button> -->
          <el-button  type="danger" size="mini" icon="el-icon-delete" @click="delHandler(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-row>
        <el-col :span="24" style="text-align:right;">
            <el-pagination background layout="total,prev, pager, next" :current-page.sync="search.current"  :page-count="search.size" :total="search.total" @current-change="sizeChangeHandler"> </el-pagination>
        </el-col>
    </el-row>
    <ComplaintTypeAdd :popDialog="updateDialog" :popValue="complaintType"  @close="closeHandler"></ComplaintTypeAdd>
  </div>
</template>
<script>
import {complaintTypePageListUrl,complaintTypeDelUrl,replaceUrlParam} from '@/utils/common'
import ComplaintTypeAdd from "./complaintType-add";

export default {
  components: {
    ComplaintTypeAdd
  },
  data() {
    return {
      pageList: [],
      complaintType: {},
      updateDialog: false,
      search: {
        current:1,
        size:10,
        total: 0,
        lkParam: {titleName:""},
        eqParam:{
              type:3
        },
      }
    };
  },
  mounted() {
    this.loadPageList();
  },
  methods: {
    addHandler: function () {
      this.complaintType={type:3}
      this.complaintType.titleParent=0
      this.complaintType.titleLevel = 1
      this.updateDialog = true;
    },
    addSubHander: function(index,row){
      this.complaintType={type:3}
      this.complaintType.titleParent= row.titleId
      this.complaintType.titleLevel = row.titleLevel+1
      this.updateDialog = true
    },
    updateHandler:function(index,row){
      this.complaintType = row;
      this.updateDialog = true;
    },
    closeHandler: function () {
      this.updateDialog = false;
      this.loadPageList();
    },
    /**
     * 删除用户
     */
    delHandler: function (index, row) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", { confirmButtonText: "确定", cancelButtonText: "取消", type: "warning" })
        .then(() => {
          this.axios
            .post(replaceUrlParam(complaintTypeDelUrl,[row.titleId]))
            .then(response => {
              if(response.data.status=="SUCCESS"){
                console.log(response)
                this.$message({ type: "success", message: "删除成功!"  });
                this.loadPageList();
              }else{
                 this.$message({ type: "warn", message: response.data.result });
              }
               
            })
            .catch(response => {
                console.log(response)
                this.$message({ type: "warn", message: "删除失败!"  });
            });
        })
        .catch(() => {
          this.$message({ type: "info", message: "已取消删除" });
        });
    },
    loadPageList() { //加载数据分页列表
      this.axios
        .post(complaintTypePageListUrl, this.search)
        .then(response => {
          var data = response.data.data;
          this.pageList = data.records;
          this.search.total = data.total;

        })
        .catch(response => {
          console.log("response -   " + response);
        });
    },
    sizeChangeHandler: function (value) {
      this.search.current = value;
      this.loadPageList();
    },
    searchHandler: function () {
      this.search.current=1
      this.loadPageList();
    }
  }
};
</script>
<style scoped>
.grid-content {
  text-align: left;
  height: 45px;
}
</style>
